/**
 * Thinking in java 
 *  2018/08/01
 */
package com.dzb.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author dzb
 * @date 2018年8月15日 上午10:05:16
 * @description    同步阻塞IO
 * @version 1.0.0
 */
public class TimeServer {
	
	// 一个请求过来，会新开一个线程进行处理
	// 处理请求的线程池
 
	
	public static void main(String[] args) {
		
		ServerSocket server =null;
		Socket socket=null;
		int port= 8080;//定义端口
		if(args!=null&&args.length>0){
			port = Integer.valueOf(port);
		}
		
		
		try {
			//创建通道
			server = new ServerSocket(port);
			System.out.println("this is time server port: "+port);
			TimeServerHandlerExecutePool threadPoolExecute= new TimeServerHandlerExecutePool(50, 10000);
			while(true){
				//接收数据的传输
				socket = server.accept();
				threadPoolExecute.execute(new TimeServerHandler(socket));
				//new Thread(new TimeServerHandler(socket)).start();
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		if(server!=null){
			System.out.println("server close ");
			try {
				server.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
			server=null;
		}
	
	}
	
	

}
